//
//  housedynamicTableViewCell.m
//  sellHouse
//
//  Created by 李 佳伟 on 2018/11/22.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "housedynamicTableViewCell.h"
#import "JTCSM.h"
#import "HouserInfoModel.h"


static CGFloat viewheight = 39;
@interface housedynamicTableViewCell ()
{
    UIView *keepview;
}

@end
@implementation housedynamicTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
        
        
    }
    
    return self;
}


- (void)layoutTargetViewWithnumber:(NSMutableArray *)list{
    
    [self removevie];
    
    UILabel *titlelabel= [UILabel initWithFrame:CGRectMake(Kspace, 0, KSCREENWidth-2*Kspace, 50) text:@"卖房动态" font:15 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(51, 51, 51, 1) backgroundColor:nil];
    [self.contentView addSubview:titlelabel];
    [df lineViewWithHeightofTop:50 superView:self.contentView lineHeight:1 space:Kspace];
    
    keepview = [[UIView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(titlelabel), KSCREENWidth, 18)];
    [self.contentView addSubview:keepview];
    CGFloat diansize = 11;
    CGFloat changespace = 4;
    CGFloat tiemlabelwidth = 50;
    CGFloat linewidth = 1;
    CGFloat changeHeight = 0;
    for (int i = 0; i<list.count; i++) {
        
        HouserInfoModel *model = list[i];
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(Kspace, KVIEW_Y(keepview)+changeHeight, KSCREENWidth-2*Kspace, viewheight)];
        [self.contentView addSubview:view];
        
        UIView *dianview = [[UIView alloc]initWithFrame:CGRectMake(changespace, 10, diansize, diansize)];
        dianview.backgroundColor = RGBACOLOR(15,166,232,1);
        [df layerWithView:dianview radius:diansize/2 width:0 color:nil];
        [view addSubview:dianview];
        UIView *topline = [[UIView alloc]initWithFrame:CGRectMake(changespace+(diansize-linewidth)/2, 0, linewidth, 10)];
        topline.backgroundColor = RGBACOLOR(241, 241, 241, 1);
        [view addSubview:topline];
        
        UIView *downline = [[UIView alloc]initWithFrame:CGRectMake(changespace+(diansize-linewidth)/2, KVIEW_Y(dianview), linewidth, 18)];
        downline.backgroundColor = RGBACOLOR(241, 241, 241, 1);
        [view addSubview:downline];
        
        UILabel *tiemlabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(dianview)+8, 7, tiemlabelwidth, 17) text:model.createDate  font:15 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(133, 133, 133, 1) backgroundColor:nil];
        [view addSubview:tiemlabel];
        
        UILabel *contentlabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(tiemlabel)+20, 7, view.frame.size.width-changespace-diansize-8-tiemlabelwidth-20, 17) text:model.content  font:15 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        [view addSubview:contentlabel];
        
        if (model.contentDetail == nil || [model.contentDetail isEqualToString:@""]) {
            changeHeight =  viewheight +changeHeight;
        }else{
            UIView *bottomview = [[UIView alloc]initWithFrame:CGRectMake(Kspace, KVIEW_Y(view), KSCREENWidth-2*Kspace,(i==list.count-1)?viewheight/2:viewheight)];
            [self.contentView addSubview:bottomview];
            UIView *line = [[UIView alloc]initWithFrame:CGRectMake(changespace+(diansize-linewidth)/2, 0, linewidth, viewheight)];
            line.backgroundColor = RGBACOLOR(241, 241, 241, 1);
            [bottomview addSubview:line];
            UILabel *bottomcontentlabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(tiemlabel)+20, 0, view.frame.size.width-changespace-diansize-8-tiemlabelwidth-20, 17) text:model.contentDetail font:15 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
            [bottomview addSubview:bottomcontentlabel];
            [df fuwenbenLabel:bottomcontentlabel FontNumber:[UIFont systemFontOfSize:15] AndRange:NSMakeRange(model.contentDetail.length-11, 11) AndColor:RGBACOLOR(255, 135, 38, 1)];
            changeHeight =  viewheight*2 +changeHeight;
        }
        
    }
    
   UIView *view= [df lineViewWithHeightofTop:KVIEW_Y(keepview)+changeHeight+20 superView:self.contentView lineHeight:20 space:0];
    view.backgroundColor = [UIColor whiteColor];
}

- (void)removevie{
    for (UIView *view in [self.contentView subviews]) {
        for (UIView *subview in [view subviews]) {
            [subview removeFromSuperview];
        }
        [view removeFromSuperview];
    }
}

@end
